package com.tvunetworks.center.device.service.impl;

import com.tvunetworks.center.device.mapper.CustomizedTShareAccountMapper;
import com.tvunetworks.center.device.model.CustomizedTShareAccount;
import com.tvunetworks.center.device.service.CustomizedTShareAccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @program: tvucc-aggregator
 * @description: CustomizedTShareAccountServiceImpl
 * @author lebronchen
 * @create: 2020-03-18 11:07
 **/
@Service
@Slf4j
public class CustomizedTShareAccountServiceImpl extends BaseService<CustomizedTShareAccount> implements CustomizedTShareAccountService {

    @Autowired
    private CustomizedTShareAccountMapper customizedTShareAccountMapper;

    @Override
    public CustomizedTShareAccount getTShareAccountExist(String peerId, String deviceName) {
        CustomizedTShareAccount record = new CustomizedTShareAccount()
                .setPeerId(peerId)
                .setDeviceName(deviceName);
        return super.selectExistOne(record);
    }

    @Override
    @Transactional
    public CustomizedTShareAccount addTShareAccount(CustomizedTShareAccount customizedTShareAccount) {
        super.insert(customizedTShareAccount);
        return customizedTShareAccount;
    }

    @Override
    public CustomizedTShareAccount getByShareId(String shareId) {
        CustomizedTShareAccount record = new CustomizedTShareAccount()
                .setShareId(shareId);
        return super.selectOne(record);
    }

    @Override
    public boolean isFixedShareAccount(String shareId) {
        CustomizedTShareAccount account = this.getByShareId(shareId);
        return account != null;
    }

    @Override
    public List<String> listAllShareIds() {
        return customizedTShareAccountMapper.listAllShareIds();
    }

    @Override
    public void deleteById(String id) {
        super.deleteLogicById(id);
    }
}
